package cms.manage.template.value.impl;

import cms.bean.PageView;
import cms.bean.template.Forum;
import cms.bean.topic.Comment;
import cms.bean.topic.Tag;
import cms.bean.topic.Topic;
import cms.manage.template.impl.TagTemplateManage;
import cms.manage.template.impl.TopicTemplateManage;
import cms.manage.template.value.TplValueStrategy;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import static cms.common.SystemConstant.DisplayType.*;

@Service("话题")
public class TopicStrategy implements TplValueStrategy {

    @Resource
    TopicTemplateManage topicTemplateManage;//话题 -- 模板方法实现
    @Resource
    TagTemplateManage tagTemplateManage;//标签 -- 模板方法实现

    @Override
    public Object doOperation(Forum forum, Map submitParameter, Map runtimeParameter) {
        if(StringUtils.equals(forum.getForumChildType(),"标签列表")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                List<Tag> value = tagTemplateManage.tagCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("话题列表")){
            if(forum.getDisplayType().equals(DISPLAY_PAGE.getValue())){//分页
                PageView<Topic> value = topicTemplateManage.topicPage(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("相似话题")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                List<Topic> value = topicTemplateManage.topicLikeCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("话题取消隐藏")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = topicTemplateManage.topicUnhideCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("话题内容")){
            if(forum.getDisplayType().equals(DISPLAY_ENTITYBEAN.getValue())){//实体对象
                Topic value = topicTemplateManage.contentEntityBean(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("添加话题")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = topicTemplateManage.addTopicCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("修改话题")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = topicTemplateManage.editTopicCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("评论列表")){
            if(forum.getDisplayType().equals(DISPLAY_PAGE.getValue())){//分页
                PageView<Comment> value = topicTemplateManage.commentPage(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("添加评论")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = topicTemplateManage.addCommentCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("引用评论")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = topicTemplateManage.quoteCommentCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("修改评论")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = topicTemplateManage.editCommentCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("回复评论")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = topicTemplateManage.replyCommentCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("修改评论回复")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = topicTemplateManage.editCommentReplyCollection(forum, submitParameter,runtimeParameter);
                return value;
            }
        }
        return null;
    }
}
